<?php
include '../c/config.php';
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqli->error);}

 
$query=$mysqli->query("SELECT * FROM `ti` where  step=1   ");
$yiDan=array();
while ($list=$query->fetch_array()) {
    $yiDan[$list['id']]=$list['dan'];

}
//var_dump($yiDan);
echo "<br /><br />";
 

$query=$mysqli->query("SELECT yi,id FROM `d6` WHERE fen is NULL  limit 0,1 ");
while ($list=$query->fetch_assoc()) {
   $userYi=json_decode($list['yi'], true);
   $userDui=0;
   foreach ($userYi as $key => $value) {
       if ($value == $yiDan[$key]) {
           $userDui++;
           echo $key,"...",$value,'.....',$yiDan[$key];
           echo "<br />";
       }
   }

  echo $userDui;
  echo "<br /><br />";
   var_dump($userYi);
 echo "<br /><br />";

   $sql="update `d6` set fen=".$userDui." WHERE id='".$list['id']."'";
    $mysqli->query($sql);
    echo $sql;
}
?>
<script type="text/javascript">
    window.setTimeout(function(){
         window.location.reload();
    }, 400);

</script>



<?php







exit;
$sql="SELECT *  FROM `uinfo` WHERE `fen` IS NULL  ORDER BY `id`  LIMIT 0,1";
 
$query=$mysqli->query($sql);
if($query->num_rows>0){
   $getU=$query->fetch_assoc();
   $uid=$getU['uid'];
   $phone=$getU['phone'];
   $updateId=$getU['id'];
   $nianji=$getU['nianji'];

   //var_dump($getU);

  // echo "<br /><br />";
   echo $uid,"........",$phone;
    echo "<br /><br />";
}else{
    exit;
}

$fen=0;
$dTable='';
if (3 == $nianji) {
   $dTable='d3'; 
}
if (4 == $nianji) {
   $dTable='d4'; 
}
if (5 == $nianji) {
   $dTable='d5'; 
}
if (empty($dTable)) {
  echo "error nianji";
  exit;
}
//echo "SELECT dui FROM `".$dTable."` where uid='".$uid."' and phone='".$phone."' limit 0,5 ";
// echo "<br /><br />";
$query=$mysqli->query("SELECT dui FROM `".$dTable."` where uid='".$uid."' and phone='".$phone."' limit 0,6 ");
while ($list=$query->fetch_assoc()) {
   $dui=$list['dui'];
   echo 'dui: ',$dui;
   echo "<br />";
   if ($fen < $dui) {
      $fen=$dui;
   }

}

 
echo "<br />";
echo $fen;
echo "<br /><br />";


$sql="update `uinfo` set fen=".$fen." WHERE id='".$updateId."'";
$query=$mysqli->query($sql);
echo $sql;
 
?>
<script type="text/javascript">
    window.setTimeout(function(){
         window.location.reload();
    }, 400);

</script>